<template>
    <div v-show="setlink != 1">
        <div :style="{minHeight:winheight + 'px'}" style="background-image: linear-gradient(to bottom, #92bdff, #fff);">
            <div style="text-align: center;" :style="{padding:sys.windowHeight/sys.windowWidth<1.5?'200rpx 0':'250rpx 0'}">
                <div style="display:inline-block;position:relative;">
                    <!-- <div v-if="(setlink == 1 || setlink == 2)&&!(statustext == '断开连接'&&hadsearch == 0)" style="position: absolute;top:0;left:0;width:100%;height:100%;background-color: #0072e8;border-radius: 50%;z-index: 3;opacity: 1; animation:meter_anmima2 3000ms infinite">
                        2.2
                    </div>
                    <div v-if="(setlink == 1 || setlink == 2)&&!(statustext == '断开连接'&&hadsearch == 0)" style="position: absolute;top:0;left:0;width:100%;height:100%;background-color: #0072e8;border-radius: 50%;z-index: 2;opacity: 1;animation:meter_anmima3 3000ms infinite">
                        3
                    </div>
                    <div v-if="(setlink == 1 || setlink == 2)&&!(statustext == '断开连接'&&hadsearch == 0)" style="position: absolute;top:0;left:0;width:100%;height:100%;background-color: #0072e8;border-radius: 50%;z-index: 1;opacity: 1;animation:meter_anmima4 3000ms infinite">
                        4
                    </div> -->
                    <div v-if="( setlink == 2)&&!(statustext == '断开连接'&&hadsearch == 0)" style="position: absolute;top:0;left:0;width:100%;height:100%;background-color: #0072e8;border-radius: 50%;z-index: 3;opacity: 1; animation:meter_anmima2 3000ms infinite">
                        <!-- 2.2 -->
                    </div>
                    <div v-if="( setlink == 2)&&!(statustext == '断开连接'&&hadsearch == 0)" style="position: absolute;top:0;left:0;width:100%;height:100%;background-color: #0072e8;border-radius: 50%;z-index: 2;opacity: 1;animation:meter_anmima3 3000ms infinite">
                        <!-- 3 -->
                    </div>
                    <div v-if="( setlink == 2)&&!(statustext == '断开连接'&&hadsearch == 0)" style="position: absolute;top:0;left:0;width:100%;height:100%;background-color: #0072e8;border-radius: 50%;z-index: 1;opacity: 1;animation:meter_anmima4 3000ms infinite">
                        <!-- 4 -->
                    </div>
                    <div style="position: absolute;top:0;left:0;width:100%;height:100%;z-index: 1;opacity: 1;transform: scale(2.6);">
                        <image :src="btnOffbg" style="width:100%;height:100%"></image>
                    </div>
                    <div style="position: relative; width:250rpx;height:250rpx;line-height: 250rpx; margin: auto;box-shadow: 0 0 10rpx 0 #999; border-radius: 50%;text-align: center;font-size: 30rpx;background-color: white;z-index: 30;">
                        <image v-if="setlink == 1" :src="btnOfficon" style="position: relative;top:-6rpx; display: inline-block; height: 83rpx;width:83rpx;vertical-align: middle;"></image>
                        <image v-else-if="(setlink == 2&&hadsearch == 1)" @click="closebluet" :src="btnOnicon" style="position: relative;top:-6rpx; display: inline-block; height: 83rpx;width:83rpx;vertical-align: middle;"></image>
                        <span v-else-if="statustext == '断开连接'&&hadsearch == 0" style="display:inline-block; vertical-align: middle;" @click="tosearch">
                            点我搜索
                        </span>
                        <image v-else-if="(setlink == 1 || setlink == 2)&&statustext == '断开连接'&&hadsearch == 1" :src="btnOnicon" style="position: relative;top:-6rpx; display: inline-block; height: 83rpx;width:83rpx;vertical-align: middle;"></image>
                        <span v-else style="display:inline-block; vertical-align: middle;" @click="tolink">
                            <!-- 设备连接 -->
                            <image :src="btnOfficon" style="position: relative;top:-6rpx; display: inline-block; height: 83rpx;width:83rpx;vertical-align: middle;"></image>
                        </span>
                        <!-- <image v-else :src="btnOfficon" style="position: relative;top:-6rpx; display: inline-block;height: 83rpx;width:83rpx;vertical-align: middle;"></image>   -->
                    </div>
                </div>
            </div>
            <div v-if="!tolinkflag" @click="tolink" style="text-align: center;"></div>
            <div v-else @click="tolink" style="position: relative;z-index: 2; margin-top: -150rpx; text-align: center;">
                <div class="textMessage fdc _white" v-if="typechange == 0">
                    <p class="bold fs48 lh45">常用设备列表</p>
                    <p class="fs28 paddingAll bold p2">选择设备进行连接</p>
                </div>
                <div class="textMessage fdc _white" v-if="typechange == 1">
                    <p class="bold fs48 lh45">搜索中...</p>
                    <p class="fs28 paddingAll bold p2">{{devicesData.length?'找到如下设备，请选择连接':'正在搜索可用设备'}}</p>
                </div>
            </div>
            <div style="padding-bottom:100rpx">
                <!-- <div style="padding: 60rpx 0 0;" v-if="devicesData.length == 0 && typechange == 1"></div>
                <selectDevice :status="status" v-if="status == 3 && showSelectDevice && tolinkflag && typechange == 1" @checkDevice="connectionBluetooth" @resetlinklist="resetlinklist"
                    :devicesData="devicesData" pagetype="index">
                </selectDevice>
                <onceuseinglist v-if="status == 3 && showoncedevicesData && oncedevicesData.length && typechange == 0" @checkDevice="connectionBluetooth2" @resetlinklist="resetlinklist2"
                :devicesData="oncedevicesData" pagetype="index"></onceuseinglist>
                <div style="padding:20rpx 0; text-align: center;margin-top:50rpx" v-if="oncedevicesData.length && hadsearch && (showoncedevicesData || showSelectDevice)">
                <span style="padding:10rpx 20rpx;border:2rpx solid #1993fb;color:#1993fb;" @click="typechange == 0?typechange = 1:typechange = 0">{{ typechange == 0?'切换到搜索列表':'返回到常用设备列表' }}</span>
                </div> -->
                <div style="padding: 60rpx 0 0;margin-top:-30rpx" v-if="devicesData.length == 0 && typechange == 1"></div>
                <!-- <div style="padding:20rpx;font-size: 30rpx;" v-if="showoncedevicesData && oncedevicesData.length && typechange == 1">常用设备列表</div> -->
                <!-- <onceuseinglist v-if="status == 3 && showoncedevicesData && oncedevicesData.length" @checkDevice="connectionBluetooth2" @resetlinklist="resetlinklist2"
                :devicesData="oncedevicesData" pagetype="index"></onceuseinglist> -->
                <!-- <div style="padding:20rpx;font-size: 30rpx;" v-if="showoncedevicesData && oncedevicesData.length && typechange == 1">查看可用设备</div> -->
                <selectDevice :status="status" v-if="status == 3 && showSelectDevice && tolinkflag && typechange == 1" @checkDevice="connectionBluetooth" @resetlinklist="resetlinklist"
                    :devicesData="devicesData" pagetype="index">
                </selectDevice>
            </div>
            <!-- <div v-if="status == 3 && tolinkflag" @click="closebluet">
                <span class="logintypebtn" style="display: block;margin: 20rpx auto 0;padding: 30rpx 33rpx; width:560rpx;text-align: center;background-color: #9ec8e6;color: white;border-radius: 50rpx;">{{statustext}}</span>
            </div> -->
        </div>
        <van-overlay :zIndex="900" :show="showLoding">
            <van-loading v-if="showLoding" custom-class="lodingBox" type="spinner" vertical color="#ffffff" size="60px">
                <p class="white fs32" style="margin-bottom:30rpx">{{ loadingText1 }}</p>
                <p class="white fs32">{{ loadingText }}</p>
            </van-loading>
        </van-overlay>
        <van-overlay :show="failinitsflag">
            <div style="width:100%;height:100%;text-align:center;" :style="{lineHeight:winheight + 'px'}">
                <div style="position:relative; display:inline-block; width:600rpx;height:400rpx;background-color:white;line-height:normal;border-radius: 18rpx;vertical-align:middle">
                    <div style="position:absolute;top:0;right:0;padding:0rpx 20rpx;font-size:50rpx;color:#8C8C8C" @click="failinitsflag = 0,toback()">×</div>
                    <div style="padding-top:60rpx; text-align:center;">
                        <span style="display:inline-block;padding:20rpx 0;background-color:#3865FE;border-radius:60rpx;box-shadow:0 0 30rpx 0 #7e96e8">
                        <image :src="blueticon" style=" height: 123rpx;width:123rpx;"></image>  
                        </span>
                    </div>
                    <div style="padding-top:72rpx; text-align:center;font-size: 28rpx;">{{ failinitsstatus == 10001?'请打开您的蓝牙设备':(failinitsstatus == 'locals'?'定位未打开，请打开定位搜索':(failinitsstatus == 'linkfail'?'连接失败，请检查设备是否正常运行...':'初始化蓝牙失败')) }}</div>
                </div>
            </div>
        </van-overlay>
    </div>
</template>

<script>
    import selectDevice from "@/components/utils/selectDevice";
    import onceuseinglist from "@/components/utils/onceuseinglist";
    import { BluetoothMode } from "../../../utils/bluetooth/bluetooth.js";
import utils from '../../../utils/index.js';
    export default {
        data(){
            return {
                sys:wx.getSystemInfoSync(),
                failinitsstatus:0,
                failinitsflag:0,
                winheight: wx.getSystemInfoSync().windowHeight,
                blueticon:require('../../../assets/bluet.png'),
                btnOnicon:require('../../../assets/btnOn.png'),
                btnOfficon:require('../../../assets/btnOff.png'),
                btnOffbg:require('../../../assets/btnOfbg.png'),
                //
                status:3,
                statustext:'点击连接蓝牙',
                typechange:0,//0就是设备列表，否则就是搜索列表
                showSelectDevice:true,
                showoncedevicesData: false,
                devicesData:[],
                oncedevicesData: [],
                timeTer:null,
                tolinkflag:0,
                loads:0,
                setlink:0,
                hadsearch:0,
                //
                loadingText1: '',
                loadingText: '',
                showLoding : false,
                ifgetlocals:0,
                //
                searchnotfoundflags:0,
                hadstopsearch:0
            }
        },
        components:{
            selectDevice,
            onceuseinglist,
        },
        methods:{
            loadoncedata(){
            var that = this
            this.searchnotfoundflags = 0
            clearTimeout(this.showdefaultloadingflag) 
            this.oncedevicesData = []
            this.globalData.nowdates = new Date().getTime()
            setTimeout(()=>{
                this.oncedevicesData = wx.getStorageSync('oncedevicesData')||[]
                //
                for(var i=0;i<that.oncedevicesData.length;i++){
                if(wx.getStorageSync('modelseletmodedate')&&wx.getStorageSync('modelseletmodedate')['t_'+that.oncedevicesData[i].deviceId]){
                    that.oncedevicesData[i].date = new Date(wx.getStorageSync('modelseletmodedate')['t_'+that.oncedevicesData[i].deviceId]).getTime()
                }else{
                    that.oncedevicesData[i].date = 0
                }
                }
                that.oncedevicesData = that.oncedevicesData.sort((a,b)=>b.date-a.date)
                //
                var alluse = []
                var noalluse = []
                for(var i=0;i<that.oncedevicesData.length;i++){
                if(that.oncedevicesData[i].deviceId == wx.getStorageSync('alluserModelId')){
                    that.oncedevicesData[i].alluse = 1
                    alluse.push(that.oncedevicesData[i])
                }else{
                    that.oncedevicesData[i].alluse = 0
                    noalluse.push(that.oncedevicesData[i])
                }
                }
                that.oncedevicesData = alluse.concat(noalluse)
            })
            },
            tolink(){
                this.tolinks = 0
                this.nowdates = Number((this.globalData.nowdates).toString())
                if(this.setlink == 1){
                    return
                }
                this.setlink = 1
                setTimeout(()=>{
                    var temp = -1
                    this.globalData.bluetooth.initBluetooth((err)=>{
                        temp = err.errMsg.indexOf('startBluetoothDevicesDiscovery:fail')
                    },(inits)=>{
                        if(inits != 'none'){
                            if(inits && inits.errCode && inits.errCode == 10001){
                            this.failinitsstatus = 10001
                            this.failinitsflag = 1
                            }else{
                            this.failinitsstatus = 1
                            this.failinitsflag = 1
                            }
                        }
                    },()=>{
                        if(!this.ifgetlocals){
                            this.failinitsstatus = 'locals'
                            this.failinitsflag = 1
                        }
                    }).then((res) => {
                        this.ifgetlocals = 1
                        setTimeout(()=>{
                            if(temp == -1){
                                this.setlink = 2
                                this.statustext = '断开连接'
                                this.tolinkflag = 1
                                this.showoncedevicesData = true
                                // if(!this.oncedevicesData.length){
                                    this.tosearch()
                                // }
                                // if(this.oncedevicesData[0].alluse){
                                //     this.connectionBluetooth2(this.oncedevicesData[0])
                                // }
                                // this.getmodellist()
                            }else{
                                // wx.showModal({
                                //     title:'提示',
                                //     content:'蓝牙连接失败'
                                // })
                                this.setlink = 0
                            }
                        },0)
                    })
                },0)
            },
            searchnotfoundflag(){
            if(this.searchnotfoundflags == 0){
                this.searchnotfoundflags = 1
                clearTimeout(this.tosearchnotfound)
                this.tosearchnotfound = setTimeout(()=>{
                if(this.globalData.weighttestpageshow == 1){
                    if(this.nowdates != this.globalData.nowdates){
                    return;
                    }                    
                    if(this.devicesData.length){
                    this.searchnotfoundflags = 0
                    this.searchnotfoundflag()
                    }else if(this.typechange == 1 && this.hadsearch == 1 && this.setlink == 2){
                    wx.showModal({
                        title:'提示',
                        content:'搜索不到设备，请确保设备已开机',
                        showCancel:false,
                        success:res=>{
                            this.searchnotfoundflags = 0
                            this.searchnotfoundflag()
                        }
                    })
                    }
                }
                },15000)
            }
            },
            closebluet(type){
                if(!type){
                    wx.showModal({
                        title:'提示',
                        content:'确定断开吗？',
                        success:res=>{
                            this.globalData.islinkingbluemodel = {}
                            this.setlink = 0
                            this.statustext = '点击连接蓝牙'
                            this.tolinkflag = 0
                            this.globalData.bluetoothflag = 0
                            this.globalData.righttop_bluetoothobj = null
                            this.showoncedevicesData = false
                            this.showSelectDevice = false
                            this.hadsearch = 0;
                            this.typechange = 0
                            this.globalData.bluetooth.subscribers['newDevice'] = undefined

                            wx.removeStorageSync('defaultmodel_index')
                            this.globalData.bluetooth.close()
                        }
                    })
                }else{
                    this.globalData.islinkingbluemodel = {}
                    this.setlink = 0
                    this.statustext = '点击连接蓝牙'
                    this.tolinkflag = 0
                    this.globalData.bluetoothflag = 0
                    this.globalData.righttop_bluetoothobj = null
                    this.showoncedevicesData = false
                    this.showSelectDevice = false
                    this.hadsearch = 0;
                    this.typechange = 0
                    this.globalData.bluetooth.subscribers['newDevice'] = undefined

                    wx.removeStorageSync('defaultmodel_index')
                    this.globalData.bluetooth.close()
                }
            },
            resetlinklist(data){
                this.devicesData = []
                setTimeout(()=>{
                    this.devicesData = data.data
                })
            },
            tosearch(){
                if(this.hadstopsearch == 1){
                    this.hadstopsearch = 0
                    this.globalData.bluetooth.stop();
                    setTimeout(()=>{
                        this.globalData.bluetooth._handlersearch()
                        if(this.hadsearch == 0){
                            this.hadsearch = 1
                            this.getmodellist()
                        }
                    },100)
                    return;
                }
                if(this.hadsearch == 0){
                    this.hadsearch = 1
                    this.getmodellist()
                }
            },
            getmodellist(type){
                if(!type){
                    if(wx.getStorageSync('alluserModelIdName')){
                        this.showLoding = true;
                        this.loadingText1 = "正在搜索默认设备"
                        this.loadingText = wx.getStorageSync('alluserModelIdName');
                        this.showdefaultloadingflag = setTimeout(()=>{
                            this.showLoding = false;
                            this.loadingText1 = ""
                            this.searchnotfoundflag()
                        },10000)
                    }else{
                        this.searchnotfoundflag()
                    }
                }
                var that = this;
                this.hadsearch = 1
                this.typechange = 1
                // 监听发现新的设备
                this.timeTer = setTimeout(() => {
                this.globalData.bluetooth.on("newDevice", (data) => {
                    that.devicesData = []
                    this.loads = 1
                    console.log(134314, "resres", data);
                    // wx.showToast({
                    // 'icon':'none',
                    // title:'搜索设备完毕'
                    // })
                    console.log(
                        "RSSI" + data.sort(that.createComparisonFunction("RSSI"))
                    );
                    if(data&&data.length){
                        that.devicesData = data.sort(
                        that.createComparisonFunction("RSSI")
                        );
                        //
                        for(var i=0;i<that.devicesData.length;i++){
                        if(wx.getStorageSync('modelseletmodedate')&&wx.getStorageSync('modelseletmodedate')['t_'+that.devicesData[i].deviceId]){
                            that.devicesData[i].date = new Date(wx.getStorageSync('modelseletmodedate')['t_'+that.devicesData[i].deviceId]).getTime()
                        }else{
                            that.devicesData[i].date = 0
                        }
                        }
                        that.devicesData = that.devicesData.sort((a,b)=>b.date-a.date)
                        //
                        setTimeout(()=>{
                            var memorydevice = []
                            for(var i=0;i<that.oncedevicesData.length;i++){
                                memorydevice.push(that.oncedevicesData[i].deviceId) 
                            }
                            var hadmemory = []
                            var nohadmemory = []
                            for(var i=0;i<that.devicesData.length;i++){
                            if(memorydevice.indexOf(that.devicesData[i].deviceId) != -1){
                                that.devicesData[i].memo = 1
                                hadmemory.push(that.devicesData[i])
                            }else{
                                that.devicesData[i].memo = 0
                                nohadmemory.push(that.devicesData[i])
                            }
                            }
                            var lastarrs = utils.depcl({arr:hadmemory.concat(nohadmemory)})
                            setTimeout(()=>{
                                that.devicesData = lastarrs.arr
                                console.log('')
                                setTimeout(()=>{
                                    //
                                    var alluse = []
                                    var noalluse = []
                                    for(var i=0;i<that.devicesData.length;i++){
                                    if(that.devicesData[i].deviceId == wx.getStorageSync('alluserModelId')){
                                        that.devicesData[i].alluse = 1
                                        alluse.push(that.devicesData[i])
                                    }else{
                                        that.devicesData[i].alluse = 0
                                        noalluse.push(that.devicesData[i])
                                    }
                                    }
                                    that.devicesData = alluse.concat(noalluse)
                                    that.showSelectDevice = that.devicesData.length > 0 ? true : false;
                                    if(that.devicesData[0].alluse && !that.tolinks){
                                        that.closeBLEConnection(that.devicesData[0].deviceId,1)
                                        clearTimeout(that.showdefaultloadingflag) 
                                        that.tolinks = 1
                                        that.showLoding = true
                                        that.loadingText1 = that.devicesData[0].localName || that.devicesData[0].name
                                        that.loadingText = '正在连接默认设备'
                                        setTimeout(()=>{
                                            that.connectionBluetooth(that.devicesData[0])
                                        },4500)
                                    }
                                })
                            })
                        })
                    }
                    console.log("devicesData" + that.devicesData[0],that.devicesData.length);

                    that.showSelectDevice = that.devicesData.length > 0 ? true : false;
                    //
                    // that.globalData.bluetooth.stop();
                    // that.globalData.bluetooth._handlersearch()
                    // this.getmodellist(1)
                });
                }, 500);
            },
            createComparisonFunction(propertyName) {
            //根据rssi大小排列
            return function (object1, object2) {
                var value1 = object1[propertyName];
                var value2 = object2[propertyName];
                if (value1 < value2) {
                return -1;
                } else if (value1 > value2) {
                return 1;
                } else {
                return 0;
                }
            };
            },
            connectionBluetooth(e){
                this.forconnectionBluetooth(e,1)
            },
            connectionBluetooth2(e){
                this.forconnectionBluetooth(e)
            },
            forconnectionBluetooth(e,type){
                this.loadingText1 = (e.localName || e.name)
                this.loadingText = ''
                this.showLoding = true
                this.globalData.bluetooth.connect(e.deviceId,()=>{
                    //失败回调
                    // this.failinitsstatus = 'linkfail'
                    // this.failinitsflag = 1
                    this.loadingText1 = '连接失败'
                    this.loadingText = ''
                    wx.removeStorageSync('defaultmodel_index')
                    this.showSelectDevice = false
                    setTimeout(()=>{
                        this.showSelectDevice = true
                    },100)
                    setTimeout(()=>{
                        this.showLoding = false
                        this.loadingText1 = ''
                        this.loadingText = ''
                        this.getmodellist()
                    },3000)
                }).then((res) => {
                    this.globalData.bluetooth.stop();
                    this.loadingText1 = '连接成功'
                    this.loadingText = ''
                    this.globalData.bluetoothflag = 1
                    this.globalData.bluetoothuselisten(1)
                    this.globalData.bluetoothuselistenflag = 1
                    if(type){
                        this.saveonceusedevice(e)
                    }
                    setTimeout(()=>{
                        this.globalData.righttop_bluetoothobj = e
                        wx.setStorageSync('defaultmodel_index',{...e,...res})
                        this.globalData.islinkingbluemodel = wx.getStorageSync('defaultmodel_index')
                        this.status = 0
                        setTimeout(()=>{
                            this.status = 3
                            wx.navigateBack()
                        })
                    },3000)
                })
            },

            resetlinklist2(data){
            this.oncedevicesData = []
            setTimeout(()=>{
                this.oncedevicesData = data.data
            })
            this.loadoncedata()
            },
            //保存连过的设备
            saveonceusedevice(e){
            var temp = wx.getStorageSync('oncedevicesData') || []
            var ishere = 0
            for(var i=0;i<temp.length;i++){
                if(temp[i].deviceId == e.deviceId){
                    ishere = 1
                }
                if(wx.getStorageSync('alluserModelId')&&temp[i].deviceId == wx.getStorageSync('alluserModelId')){
                    temp[i].alluse = 1
                }else{
                    temp[i].alluse = 0
                }
            }
            //==
            var defaultset = []
            for(var i=0;i<temp.length;i++){
                if(temp[i].alluse == 1){
                    defaultset.push(temp[i])
                }
            }
            if(ishere == 0){
                temp.push(e)
                var nodefaultset = []
                for(var i=0;i<temp.length;i++){
                    if(temp[i].alluse != 1){
                        nodefaultset.push(temp[i])
                    }
                }
                var lastarr = []
                //先查找有没有默认
                setTimeout(()=>{
                    if(defaultset.length){
                        if(nodefaultset.length){
                            nodefaultset = [nodefaultset[nodefaultset.length - 1]]
                        }
                        lastarr = defaultset.concat(nodefaultset)
                    }else if(nodefaultset.length > 2){
                        lastarr = [nodefaultset[nodefaultset.length - 1],nodefaultset[nodefaultset.length - 2]]
                    }else{
                        lastarr = nodefaultset
                    }
                    //==                
                    wx.setStorageSync('oncedevicesData',lastarr)
                })
            }
            this.loadoncedata()
            },
            toback(){
                wx.navigateBack()
            },
            closeBLEConnection(deviceId,type) {
            if (deviceId) {
                wx.closeBLEConnection({
                deviceId: deviceId,
                success: function (res) {
                    //console.log("closeBLEConnection。success", res);
                },
                fail: function (res) {
                    //console.log("closeBLEConnection。fail", res);
                },
                complete: function () {
                    // status = false;
                    //console.log("closeBLEConnection。complete");
                },
                });
            }
            if(type != 1){
                wx.closeBluetoothAdapter({
                success: function (res) {
                    //console.log("closeBluetoothAdapter ==>meterres:", res);
                },
                fail: function (error) {
                    //console.log("closeBluetoothAdapter ==>metererror:", error);
                },
                });
            }
            },
        },
        onLoad(){
            this.globalData.weighttestpageshow = 1
            this.hadstopsearch = 0
            this.showLoding = false
            this.loadingText1 = ''
            this.loadingText = ''
            this.devicesData = []
            this.tolinks = 0
            this.setlink = 0
            this.loadoncedata()
            if(!this.globalData.bluetooth){
                this.globalData.bluetooth = new BluetoothMode();
            }
            if(wx.getStorageSync('defaultmodel_index')){
                this.globalData.righttop_bluetoothobj = wx.getStorageSync('defaultmodel_index')
            }
            this.loads = 0
            if(this.globalData.bluetoothflag == 1){
                // this.statustext = '断开连接'
                // this.hadsearch = 0
                // this.typechange = 1
                // this.hadstopsearch = 1
                this.tolinkflag = 0
                this.ifgetlocals = 0
                this.modelforsearch = 1
                this.typechange = 1
                this.showoncedevicesData = false
                this.showSelectDevice = false
                this.failinitsflag = 0
                this.failinitsstatus = 0

                this.statustext = '点击连接蓝牙'
                this.hadsearch = 0
                this.setlink = 0
                this.hadstopsearch = 0
                setTimeout(()=>{
                    this.tolink()
                })
                // ====
            }else{
                this.tolinkflag = 0
                this.ifgetlocals = 0
                this.modelforsearch = 1
                this.typechange = 1
                this.showoncedevicesData = false
                this.showSelectDevice = false
                this.failinitsflag = 0
                this.failinitsstatus = 0

                this.statustext = '点击连接蓝牙'
                this.hadsearch = 0
                this.setlink = 0
                this.hadstopsearch = 0
                this.closebluet(1)
                setTimeout(()=>{
                    this.tolink()
                })
            }
        },
        onUnload(){
            this.globalData.weighttestpageshow = 0
            this.globalData.nowdates = new Date().getTime()
        }
    }
</script>

<style lang="less">
    @import "../../../assets/less/common.less";
    page{
        background-image: linear-gradient(to bottom, #92bdff, #fff);
    }
    .lodingBox {
    position: fixed;
    top: 38%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    }
</style>
<style>
    @keyframes meter_anmima2 {
        0%{
            transform: scale(1);
            opacity: 1;
        }50%{
            transform: scale(1);
            opacity: .5;
        }100%{
            transform: scale(1.6);
            opacity: 0;
        }
    }
    @keyframes meter_anmima3 {
        0%{
            transform: scale(1);
            opacity: 1;
        }30%{
            transform: scale(1);
            opacity: .3;
        }100%{
            transform: scale(2.2);
            opacity: 0;
        }
    }
    @keyframes meter_anmima4 {
        0%{
            transform: scale(1);
            opacity: .4;
        }100%{
            transform: scale(2.8);
            opacity: 0;
        }
    }
</style>

<style lang="less" scoped>
.textMessage{
  margin-top: 30rpx;
  text-align: center;
  z-index: 900;
  width: 100%;
  align-items: center;
  letter-spacing: 1rpx;
  color: #6192b9;
  .p2{
    width: 80%;
  }
}
.fs48{
  font-size: 48rpx;
}
</style>